// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   UserDao.java

package com.itheima.travel.dao;

import com.itheima.travel.model.User;
import com.itheima.travel.util.JdbcUtils;
import java.sql.SQLException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class UserDao
{

	private JdbcTemplate jdbcTemplate;

	public UserDao()
	{
		jdbcTemplate = new JdbcTemplate(JdbcUtils.getDataSource());
	}

	public User getUserByUserName(String username)
		throws SQLException
	{
		String sql = "SELECT * FROM tab_user WHERE username=?";
		User dbUser = (User)jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper(com/itheima/travel/model/User), new Object[] {
			username
		});
		return dbUser;
		EmptyResultDataAccessException e;
		e;
		e.printStackTrace();
		return null;
	}

	public int addUser(User user)
		throws SQLException
	{
		String sql = "insert into tab_user values(null,?,?,?,?,?,?,?,?,?)";
		return jdbcTemplate.update(sql, new Object[] {
			user.getUsername(), user.getPassword(), user.getName(), user.getBirthday(), user.getSex(), user.getTelephone(), user.getEmail(), user.getStatus(), user.getCode()
		});
	}

	public int active(String code)
		throws SQLException
	{
		String sql = "UPDATE tab_user SET STATUS='Y' WHERE CODE=? AND STATUS='N'";
		return jdbcTemplate.update(sql, new Object[] {
			code
		});
	}
}
